package com.bzy.blp.upms.web.controller;


import com.bzy.blp.upms.service.ResourceInfoService;
import com.bzy.blp.upms.service.UserService;
import com.bzy.blp.upms.vo.ResourceInfoVO;
import com.bzy.common.bean.Result;
import com.bzy.shiro.util.SessionUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping(value = "/resource")
public class ResourcesController {

    @Autowired
    UserService userService;
    @Autowired
    ResourceInfoService resourceInfoService;

    /**
     * 查询资源
     * @param request
     * @return
     * @throws Exception
     */
    @GetMapping(value = "/resourceFind")
    public Result resourceFind(HttpServletRequest request) throws Exception {
        Result rs = new Result();
        rs.setMessage("失败");
        rs.setSuccess(false);
        String userName = (String) SessionUtil.getPrincipal();
        Long userid = userService.findUseridByUsername(userName);
        List<ResourceInfoVO> resourceInfoVOs = resourceInfoService.findResourceByUserIdTree(userid.toString(), null);
        rs.setData(resourceInfoVOs);
        rs.setMessage("成功");
        rs.setSuccess(true);
        return rs;
    }

//    /**
//     * 更新资源
//     * @param tblUpmsResourceInfoDat
//     * @param request
//     * @return
//     * @throws Exception
//     */
//    @RequestMapping(value = "/updateResource", method = RequestMethod.GET)
//    public Result updateResource(TblUpmsResourceInfoDat tblUpmsResourceInfoDat,HttpServletRequest request) throws Exception {
//        Result rs = new Result();
//        rs.setMessage("失败");
//        rs.setSuccess(false);
//        boolean isResult = resourceInfoService.updateResource(tblUpmsResourceInfoDat);
//        if(isResult){
//            rs.setMessage("成功");
//            rs.setSuccess(true);
//        }
//        return rs;
//    }
//
//    /**
//     * 添加资源
//     * @param tblUpmsResourceInfoDat
//     * @param request
//     * @return
//     * @throws Exception
//     */
//    @RequestMapping(value = "/addResource", method = RequestMethod.GET)
//    public Result addResource(TblUpmsResourceInfoDat tblUpmsResourceInfoDat,HttpServletRequest request) throws Exception {
//
//        Result rs = new Result();
//        rs.setMessage("失败");
//        rs.setSuccess(false);
//        boolean isResult = resourceInfoService.addResource(tblUpmsResourceInfoDat);
//        if(isResult){
//            rs.setMessage("成功");
//            rs.setSuccess(true);
//        }
//
//        return rs;
//    }
//
//    /**
//     * 删除资源
//     * @param tblUpmsResourceInfoDat
//     * @param request
//     * @return
//     * @throws Exception
//     */
//    @RequestMapping(value = "/deleteResource", method = RequestMethod.GET)
//    public Result deleteResource(TblUpmsResourceInfoDat tblUpmsResourceInfoDat,HttpServletRequest request) throws Exception {
//
//        Result rs = new Result();
//        rs.setMessage("失败");
//        rs.setSuccess(false);
//        boolean isResult = resourceInfoService.deleteResource(tblUpmsResourceInfoDat);
//        if(isResult){
//            rs.setMessage("成功");
//            rs.setSuccess(true);
//        }
//        return rs;
//    }

}
